package com.cloud.config.mybatis.base.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author wangjian
 * @version 1.0.0
 * @create 2020年10月15日15:48
 */
@ApiModel("分页参数")
@Data
@EqualsAndHashCode(callSuper = false)
public class PageVO<T> implements Serializable {

    /**
     * serialVersionUID,非版本变更，否则不可随意变更
     */
    private static final long serialVersionUID = 5672541742208928768L;


    @ApiModelProperty("总行数")
    @JSONField(name = "totalCount")
    @JsonProperty("totalCount")
    private Long totalCount;

    @ApiModelProperty("数据列表")
    @JSONField(name = "list")
    @JsonProperty("list")
    private List<T> list;

    public PageVO() {

    }

    /**
     * 分页
     */
    public PageVO(IPage<T> page) {
        this.list = Optional.ofNullable(page.getRecords()).orElse(Collections.emptyList());
        this.totalCount = page.getTotal();
    }

}
